package com.example.demo.service.impl;

import com.example.demo.dataobject.HealthInfo;
import com.example.demo.dataobject.UserInfo;
import com.example.demo.repository.HealthInfoRepository;
import com.example.demo.repository.UserInfoRepository;
import com.example.demo.service.HealthInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class HealthInfoServiceImpl implements HealthInfoService {


    @Autowired
    private UserInfoRepository userInfoRepository;

    @Autowired
    private HealthInfoRepository healthInfoRepository;



    @Override
    public boolean save(HealthInfo healthInfo) {
        HealthInfo result = healthInfoRepository.save(healthInfo);
        if(result!=null){
            return true;
        }
        return false;
    }

    @Override
    public HealthInfo findByTelephone(String telephone) {
        UserInfo userInfo = userInfoRepository.findByTelephone(telephone);
        HealthInfo healthInfo = healthInfoRepository.findByUserId(userInfo.getId());
        return healthInfo;
    }
}
